package com.tgu.controller;

import com.tgu.entity.request.*;
import com.tgu.service.IIconsService;
import com.tgu.service.IUsersService;
import com.tgu.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("portal/user")
public class UsersController {

    @Autowired
    private IUsersService usersService;

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable String id) {
        return usersService.getById(id);
    }

    @PostMapping("/login")
    public Result login(@RequestBody LoginReq loginReq) {
        return usersService.login(loginReq);
    }

    @PostMapping("/register")
    public Result register(@RequestBody RegisterReq registerReq) {
        return usersService.register(registerReq);
    }

    @PostMapping("/recharge")
    public Result recharge(@RequestBody RechargeReq req) {
        return usersService.recharge(req);
    }

    @PostMapping("/changeInfo")
    public Result changeInfo(@RequestBody ChangeInfoReq infoReq) {
        return usersService.changeInfo(infoReq);
    }

    @PostMapping("/uploadApprove")
    public String uploadApprove (HttpServletRequest req, @RequestParam("file") MultipartFile file, Model m) {
        return usersService.upLoadApprove(req, file, m);
    }

    @GetMapping("/getUploadedApprove/{fileName}")
    public byte[] getUploadedApprove(@PathVariable String fileName) {
        return usersService.getUploadedApprove(fileName);
    }

    @PostMapping("/submitApprove")
    public Result submitApprove(@RequestBody SubmitApproveReq submitApproveReq) {
        return usersService.submitApprove(submitApproveReq);
    }
}
